package com.aratek.huwai.controller;

import com.aratek.huwai.common.R;
import com.aratek.huwai.dao.DishRepository;
import com.aratek.huwai.dao.ProgramRepository;
import com.aratek.huwai.dao.ProgramScoreRepository;
import com.aratek.huwai.dao.ScoreRepository;
import com.aratek.huwai.model.DishEntity;
import com.aratek.huwai.model.ProgramEntity;
import com.aratek.huwai.model.ProgramScoreEntity;
import com.aratek.huwai.model.ScoreEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * @Author 姜寄羽
 * 测试数据
 * @Date 2018/1/23 15:48
 */
@RestController
public class TestController {

    @Autowired
    DishRepository dishRepository;
    @Autowired
    ScoreRepository scoreRepository;

    @Autowired
    ProgramRepository programRepository;
    @Autowired
    ProgramScoreRepository programScoreRepository;

    @Autowired
    ApiController apiController;

    @GetMapping("/test")
    @Transactional
    public R initTestData(){
        Random random = new Random();
        for(int i = 1;i<15;i++){
            DishEntity entity = new DishEntity();
            entity.setTable(i);
            entity.setName("第"+ i + "个");
            entity.setId(i);
            dishRepository.save(entity);
        }
        for(int dishId=1;dishId<15;dishId++){
            for(int table =1;table<15;table++) {
                ScoreEntity entity = new ScoreEntity();
                entity.setId(ScoreRepository.KEY.getAndIncrement());
                entity.setDishId(dishId);
                entity.setRaterTable(table);
                entity.setTaste(random.nextInt(10)+1);
                entity.setExterior(random.nextInt(10)+1);
                entity.setOriginality(random.nextInt(10)+1);
                scoreRepository.save(entity);
            }
        }
        return R.ok();
    }

    @GetMapping("/test2")
    @Transactional
    public R initTest2Data(){
        Random random = new Random();
        for(int i = 1;i<15;i++){
            ProgramEntity entity = new ProgramEntity();
            entity.setName("第"+ i + "个节目");
            entity.setId(i);
            programRepository.save(entity);
        }
        for(int dishId=1;dishId<15;dishId++){
            for(int table =1;table<15;table++) {
                ProgramScoreEntity entity = new ProgramScoreEntity();
                entity.setId(ScoreRepository.KEY.getAndIncrement());
                entity.setProgramId(dishId);
                entity.setRaterId(table);
                entity.setScore(random.nextInt(10)+1);
                programScoreRepository.save(entity);
            }
        }
        return R.ok();
    }
}
